package br.com.virtual.base.uteis;

import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class MailUtils implements VirtualConstants {

	public static void sendHtmlMail(String conteudo, String toMail,
			String subject) {
		Properties props = new Properties();
		props.put("mail.smtp.auth", "true");
		props.put("mail.smtp.starttls.enable", "true");
		props.put("mail.smtp.host", "smtp.gmail.com"); // <<-- SERVIDOR SMTP >>
		props.put("mail.smtp.port", "587"); // <<-- PORTA -->>

		Session session = Session.getInstance(props,
				new javax.mail.Authenticator() {
					protected PasswordAuthentication getPasswordAuthentication() {
						return new PasswordAuthentication(
								EMAIL_USERNAME, EMAIL_PASSWORD); 
						}
				});

		try {
			
			MimeMessage message = new MimeMessage(session);
			
			
			message.setFrom(new InternetAddress( EMAIL_USERNAME ));
			message.addRecipient(Message.RecipientType.TO, new InternetAddress(toMail));
//			message.setSubject(subject);
			message.setSubject(subject);
			
			message.setContent(conteudo, "text/html; charset=UTF-8");
			Transport.send(message);
			
		} catch (AddressException e) {
			e.printStackTrace();
		} catch (MessagingException e) {
			e.printStackTrace();
		}
	}
}